package com.hsjk.szwj.module.system.controller.admin.file;

import com.hsjk.szwj.framework.common.enums.OssSavePlaceEnum;
import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.module.system.service.file.IOssService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/17 22:53
 **/
@Tag(name = "管理后台 - 文件处理接口")
@RestController
@RequestMapping("/system/oss")
@Validated
public class AdminOssFileController {
    @Resource
    private IOssService ossService;

    @PostMapping("/upload")
    @Operation(summary = "上传文件")
    @PreAuthorize("@ss.hasPermission('system:oss:create')")
    public CommonResult<String> uploadFile(@RequestParam("file") MultipartFile file) {
        return success(ossService.upload(OssSavePlaceEnum.PUBLIC, file));
    }
}
